import { _decorator, Collider, Component, Node, RigidBody, tween, v3 } from 'cc';
import { PoolManager } from '../AshFramework/Managers/PoolManager';
const { ccclass, property } = _decorator;

@ccclass('Bullet')
export class Bullet extends Component {
    @property
    DirZ: number = -1;

    RigidBody: RigidBody = null;
    Collider: Collider = null;
    StartPosZ: number = 0;
    Dis: number = 0;

    protected onLoad(): void {
        this.RigidBody = this.getComponent(RigidBody);
        this.Collider = this.getComponent(Collider);
    }

    protected update(dt: number): void {
        this.RigidBody.setLinearVelocity(v3(0, 0, this.DirZ * dt));
        if (Math.abs(this.StartPosZ - this.node.getPosition().z) >= this.Dis) {
            PoolManager.PutNode(this.node);
        }
    }

    init(dis: number) {
        this.StartPosZ = this.node.getPosition().clone().z;
        this.Dis = dis;
    }
}


